package com.jiot.controller.device;

import com.zg.cloud.BaseResponse;
import com.zg.cloud.CommonEnum;
import com.zg.cloud.annotation.RoleCheck;
import com.zg.cloud.annotation.TokenCheck;
import com.zg.cloud.service.AlarmFunctionalService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import req.functional.report.GetFunctionalReportReq;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author liling
 * @date 2020/11/19 14:04
 * @description
 **/
@RestController
@RequestMapping("/device/alarm/functional")
@Api(value = "职能端告警模块")
public class AlarmFunctionalController {

    @Resource
    private AlarmFunctionalService alarmFunctionalService;

    @RoleCheck({CommonEnum.Role.FUNCTIONAL})
    @PostMapping("/rate/info")
    @TokenCheck
    @ApiOperation(value = "报警响应率", notes = "device")
    public BaseResponse rateInfo() {
        return new BaseResponse(alarmFunctionalService.rateInfo());
    }

    @RoleCheck({CommonEnum.Role.FUNCTIONAL})
    @PostMapping("/every/count")
    @TokenCheck
    @ApiOperation(value = "报警信息响应数", notes = "device")
    public BaseResponse everyCount() {
        return new BaseResponse(alarmFunctionalService.everyCount());
    }

    @RoleCheck({CommonEnum.Role.FUNCTIONAL})
    @PostMapping("/type/percent")
    @TokenCheck
    @ApiOperation(value = "报警类型占比", notes = "device")
    public BaseResponse typePercent() {
        return new BaseResponse(alarmFunctionalService.typePercent());
    }

    @RoleCheck({CommonEnum.Role.FUNCTIONAL})
    @PostMapping("/industry/percent")
    @TokenCheck
    @ApiOperation(value = "报警行业占比", notes = "device")
    public BaseResponse industryPercent() {
        return new BaseResponse(alarmFunctionalService.industryPercent());
    }

    @RoleCheck({CommonEnum.Role.FUNCTIONAL})
    @PostMapping("/report")
    @TokenCheck
    @ApiOperation(value = "职能用户报表", notes = "device")
    public BaseResponse report(@RequestBody @Valid GetFunctionalReportReq getFunctionalReportReq) {
        return new BaseResponse(alarmFunctionalService.report(getFunctionalReportReq));
    }


    @ApiOperation(value = "生成月报", notes = "device", hidden = true)
    @PostMapping("/generate/month/report")
    public void generateMonthReport() {
        alarmFunctionalService.generateMonthReport();
    }

    @ApiOperation(value = "生成周报", notes = "device", hidden = true)
    @PostMapping("/generate/week/report")
    public void generateWeekReport() {
        alarmFunctionalService.generateWeekReport();
    }

    @RoleCheck({CommonEnum.Role.FUNCTIONAL})
    @PostMapping("/history/times")
    @TokenCheck
    @ApiOperation(value = "职能历史报警数", notes = "device")
    public BaseResponse historyTimes() {
        return new BaseResponse(alarmFunctionalService.historyTimes());
    }
}
